<template>
	<view class="merchant-page">
		<z-paging ref="paging" v-model="dataList" @query="queryList">
			<view slot="top">
				<view class="merchant-top">
					<view class="left-item">
						<view>固定积分: <text class="score">{{fixed_score}}</text></view>
						<view class="tips">仅限以下商家使用</view>
					</view>
					<image src="/static/common/icon_sroce.png" class="right-item"></image>
				</view>
			</view>
			<view class="merchant-list">
				<view class="merchant-item" v-for="(item,index) in dataList" :key="index"
					@click="$Tips('/pages/merchant/merchantDetail?id='+item.merchant_id)">
					<image :src="item.merchant_image" class="item-left"></image>
					<view class="item-right">
						<view class="item-title">
							<view class="item-name">{{item.merchant_name}}</view>
							<view class="item-score">剩余{{item.surplus_score}} 积分</view>
						</view>
						<view class="item-time">{{item.description}}</view>
						<view class="item-time">有效期:{{item.end_time}}</view>
					</view>
				</view>
			</view>
		</z-paging>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fixed_score: '0.00',
				dataList: [],
			}
		},
		onShow() {
			this.refreshList()
		},
		methods: {
			refreshList() {
				this.$refs.paging.scrollToTop()
				this.$refs.paging.refresh();
			},
			queryList(pageNo, pageSize) {
				this.$Api.userMerchant.getMerchantList({
					page: pageNo,
					limit: pageSize,
				}).then(res => {
					this.fixed_score = res.data.fixed_score
					this.$refs.paging.complete(res.data.list.data);
				}).catch(res => {
					this.$refs.paging.complete(false);
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.merchant-page {
		width: 100%;
		min-height: 100vh;
		background: #F6F6F8;

		.merchant-top {
			padding: 30rpx 60rpx;
			background: linear-gradient(270deg, #DDF79A 0%, #A3C616 100%);
			display: flex;
			align-items: center;
			justify-content: space-between;

			.left-item {
				font-size: 32rpx;
				color: #FFFFFF;

				.score {
					font-weight: bold;
					font-size: 48rpx;
				}

				.tips {
					margin-top: 30rpx;
					font-size: 28rpx;
					color: rgba(255, 255, 255, 0.7);
				}
			}

			.right-item {
				width: 104rpx;
				height: 96rpx;
			}
		}

		.merchant-list {
			margin: 20rpx 30rpx;

			.merchant-item {
				display: flex;
				align-items: center;
				margin-bottom: 20rpx;
				box-sizing: border-box;
				padding: 26rpx 20rpx;
				box-shadow: 0rpx 0rpx 12rpx 0rpx rgba(0, 0, 0, 0.1), inset 0rpx 2rpx 2rpx 0rpx #FFFFFF;
				border-radius: 28rpx;
				background: #ffffff;

				.item-left {
					width: 156rpx;
					height: 156rpx;
					margin-right: 20rpx;
				}

				.item-right {
					flex: 1;
					min-height: 156rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.item-title {
						display: flex;
						align-items: center;
						justify-content: space-between;

						.item-name {
							font-weight: bold;
							font-size: 32rpx;
						}

						.item-score {
							font-size: 26rpx;
							color: #A3C616;
						}
					}

					.item-time {
						font-size: 26rpx;
						color: #565656;
						margin-top: 16rpx;
					}
				}
			}
		}
	}
</style>